/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_STL_HELPER_AUTO_LOCK_H__
#define __XOS_STL_HELPER_AUTO_LOCK_H__

namespace xos_stl
{

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // auto_lock

    template< class LOCK >
    class auto_lock
    {
    public:
		auto_lock( LOCK * pLock ) : m_pLock( pLock )
		{
            m_pLock->lock();
		}
		~auto_lock()
		{
            m_pLock->un_lock();
		}
	protected:
        LOCK * m_pLock;
    };

    template< class LOCK >
    auto_lock< LOCK > & f_auto_lock( LOCK * pLock )
    {
        return auto_lock< LOCK >( pLock );
    }

} // xos_stl

#endif // __XOS_STL_HELPER_AUTO_LOCK_H__
